package com.ophiux.cs.application.user.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.application.user.dto.GetCertificateTypeRequest;
import com.ophiux.cs.application.user.dto.GetCertificateTypeResponse;
import com.ophiux.cs.application.user.service.IGetCertificateTypeAppService;
import com.ophiux.cs.domain.user.model.entity.CertificateType;
import com.ophiux.cs.infrastructure.repositories.user.CertificateTypeRepository;
import com.ophiux.utils.common.ShiftUtils;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class GetCertificateTypeAppService implements IGetCertificateTypeAppService {
	@Autowired
	CertificateTypeRepository certificateTypeRepository;

	@SuppressWarnings("unchecked")
	@Override
	public Result<List<GetCertificateTypeResponse>> GetCertificateType(GetCertificateTypeRequest dto) {
		List<GetCertificateTypeResponse> resp = new ArrayList<GetCertificateTypeResponse>();
		try {
			/**
			 * 1、验证参数是否允许为空
			 * 2、执行业务 获取返回参数 与 返回签名串
			 */
			if(!dto.isParamValid()) {
				return Result.fail(ResultEnum.requestParamFail);
			}
			
			List<CertificateType> list = certificateTypeRepository.getInfoList();
			
			resp = ShiftUtils.objToNewObjList(list, GetCertificateTypeResponse.class);
			
		} catch (Exception e) {
			log.info("程序异常：",e);
			e.printStackTrace();
			return Result.fail(ResultEnum.requestException);
		}
		return Result.success(resp);
	}

}
